<template>
  <h1>计算器练习</h1>
  <input type="text" v-model="a"><br>
  <input type="text" v-model="b"><br>
  <button @click="calc('+')">加</button>
  <button @click="calc('-')">减</button>
  <button @click="calc('*')">乘</button>
  <button @click="calc('/')">除</button>
  <br>
  <h4>结果是:{{result}}</h4>

</template>

<script setup>
import {ref} from "vue";
const a = ref('');
const b = ref('');
const result = ref('');
const calc = (o)=>{
  if(Number(b.value)===0){
    alert('除数不能为0');
    return;
  }
  result.value = eval(a.value+ o + b.value);
}
</script>

<style scoped>

</style>